package com.example.demoweb.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.example.demoweb.util.Data;
import com.example.demoweb.util.file.FileUtil;

@RestController
@RequestMapping("/file")
public class MongodbFileController {
	
	@Autowired
    private FileUtil fileUtil;
	
    /**
     * FridFs 获取图片的base64字符串
     * @throws IOException
     */
    @GetMapping("/getPictureInfo/{id}")
    public String getPictureInfo(@PathVariable("id") String id) throws IOException {
    	String resultStr = "";
    	Data<String> data = fileUtil.getBase64Info(id);
    	if(data.isSuccess()) {
    		resultStr = data.getResultData();
    		System.out.println(resultStr);
    	}
    	return resultStr;
    }
    
    @GetMapping("/viewOnline/{id}")
    public ModelAndView viewOnline(@PathVariable("id") String id) throws IOException {
    	ModelAndView mv = new ModelAndView("fileTest");
    	String resultStr = "";
    	Data<String> data = fileUtil.getBase64Info(id);
    	if(data.isSuccess()) {
    		resultStr = data.getResultData();
            mv.addObject("wxb",resultStr);
    	}
    	return mv;
    }
}
